const {
  $util,
} = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
  * 生命周期函数--监听页面加载
  */
  onLoad(options) {
    this.setData(options);
    this.loadDetail();
  },
  /**
   * 详情
  */
  loadDetail() {
    $util.request({
      url: 'entry/wxapp/edu.train.getnote',
      data: {
        onlineid: this.data.sid,
        sectionid: this.data.id,
      },
      success: (res) => {
        this.setData(res.data);
        this.setData({
          update: !!res.data.notes,
        })
      },
    });
  },
  bindIpVal(e) {
    const { id } = e.currentTarget.dataset;
    const m = {};
    m[id] = e.detail.value;
    this.setData(m);
  },
  /**
 * 提交
*/
  submit() {
    $util.request({
      url: 'entry/wxapp/edu.train.setnote',
      data: {
        nid: this.data.nid,
        notes: this.data.notes || '',
      },
      success: () => {
        wx.showToast({
          title: '提交成功',
          mask: true,
          duration: 1e3,
          success: function () {
            setTimeout(function () {
              wx.navigateBack();
            }, 1000);
          },
        });
      },
    });
  },
});
